<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
        + request.getContextPath() + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>机场跑道异物监测管理平台</title>
	<link rel="shortcut icon" type="image/x-icon" sizes="16x16" href="resources/img/casc-icon.ico">
	<script src="resources/js/jquery-3.5.1.js"></script>
	<script src="resources/js/bstable/js/bootstrap.min.js "></script>
    <link rel="stylesheet" href="resources/js/bstable/css/bootstrap.min.css">
    <script type="text/javascript">
    $(function(){
    	let loginName;
    	let editDevId;
    	let editDevRadarStatus;
    	let editDevIPCamStatus;
    	
    	/* 系统管理 */
		$("#btnSysStatus").click(function() {
			console.log("SysStatus! ");
			loginName = $('.text-info').html();
			console.log('loginName: ' + loginName);
			window.location="query?loginName=" + loginName;
			
/*  			$.ajax({
				url : 'query',
				data : {
					'loginName' : loginName
				},
				dataType : 'text',
				type : 'get',
				success : function(data) {
					console.log("进入系统管理成功!" + data);
				},
				error : function(data) {
					console.log("进入系统管理失败!" + data);
				}
			});		 */	
		});
		$("#btnSysDataSave").click(function() {
			console.log("SysDataSave! ");
			loginName = $('.text-info').html();
			window.location="query?loginName=" + loginName;
		});	
    	
    	/* 设备管理 */
		$("#btnDevLst").click(function() {
			console.log("DevLs! ");
			loginName = $('.text-info').html();
			window.location="setting?loginName=" + loginName;
		});	 
    	
    	/* 用户管理 */
		$("#btnUsrLst").click(function() {
			console.log("UsrLst! ");
			loginName = $('.text-info').html();
			window.location="users?loginName=" + loginName;
		});

    	/* 添加设备 */
		$("#btnAddDevice").click(function() {
			console.log("AddDevice! ");
			let spName = $('#addSpName').prop("value");
			let spDesc = $('#addSpDesc').val();
			let radarIP = $('#addRadarIP').val();
			let radarPort = $('#addRadarPort').val();
			let ipCamIP = $('#addIPCamIP').val();
			let ipCamName = $('#addIPCamName').val();
			let ipCamPwd = $('#addIPCamPwd').val();
			let ipCamRTSP = $('#addIPCamRTSP').val();
			console.log(spName +' '+ spDesc +' '+ radarIP +' '+ radarPort +' '+ ipCamIP +' '+ ipCamName +' '+ ipCamPwd +' '+ ipCamRTSP);
   			$.ajax({
				url : 'AddDeviceServlet',
				data : {
					'spName'    : spName,
					'spDesc'    : spDesc,
					'radarIP'   : radarIP,
					'radarPort' : radarPort,
					'ipCamIP'   : ipCamIP,
					'ipCamName' : ipCamName,
					'ipCamPwd'  : ipCamPwd,
					'ipCamRTSP' : ipCamRTSP
				},
				dataType : 'text',
				type : 'get',
				success : function(data) {
					console.log("添加设备成功!" + data);
				},
				error : function(data) {
					console.log("添加设备失败!" + data);
				}
			}); 
		});
    	
    	/* 删除设备 */
		$('tbody#dev-lst-tbody .del-device').click(function(){
			console.log('del dev: ' + $(this).attr("devId"));
			let devId = $(this).attr("devId");
    			$.ajax({
				url : 'DelDeviceServlet',
				data : {
					'devId' : devId
				},
				dataType : 'text',
				type : 'get',
				success : function(data) {
					console.log("删除设备成功!" + data);
				},
				error : function(data) {
					console.log("删除设备失败!" + data);
				}
			});
    			
		});

    	/* 修改设备前，收集信息 */
		$('tbody#dev-lst-tbody .mod-device').click(function(){
			console.log('mod dev: ' + $(this).attr("modId"));
			let devId = $(this).attr("modId");
    		$.ajax({
				url : 'ModDeviceServlet',
				data : {
					'devId' : devId
				},
				dataType : 'text',
				type : 'get',
				success : function(data) {
					console.log("获取设备成功: " + data);
					let msg = JSON.parse(data);
					console.log("json: " + msg);
					console.log("sp_id: " + msg.sp_id);
					console.log("sp_name: " + msg.sp_name);
					console.log("sp_desc: " + msg.sp_desc);
					console.log("radar_ip: " + msg.radar_ip);
					console.log("radar_port: " + msg.radar_port);
					console.log("radar_status: " + msg.radar_status);
					console.log("ipcam_ip: " + msg.ipcam_ip);
					console.log("ipcam_name: " + msg.ipcam_name);
					console.log("ipcam_pwd: " + msg.ipcam_pwd);
					console.log("ipcam_pwd: " + msg.ipcam_url);
					console.log("ipcam_name: " + msg.ipcam_status);
					
					let sp_id = msg.sp_id || "";
					editDevId = sp_id;
					let sp_name = msg.sp_name || "";
					let sp_desc = msg.sp_desc || "";
					let radar_ip = msg.radar_ip || "";
					let radar_port = msg.radar_port || "";
					let radar_status = msg.radar_status || "";
					editDevRadarStatus = radar_status;
					let ipcam_ip = msg.ipcam_ip || "";
					let ipcam_name = msg.ipcam_name || "";
					let ipcam_pwd = msg.ipcam_pwd || "";
					let ipcam_url = msg.ipcam_url || "null";
					let ipcam_status = msg.ipcam_status || "";
					editDevIPCamStatus = ipcam_status;
					
					$('#editSpName').val(sp_name);
					$('#editSpDesc').val(sp_desc);
					$('#editRadarIP').val(radar_ip);
					$('#editRadarPort').val(radar_port);
					$('#editIPCamIP').val(ipcam_ip);
					$('#editIPCamName').val(ipcam_name);
					$('#editIPCamPwd').val(ipcam_pwd);
					$('#editIPCamRTSP').val(ipcam_url);
					
					
				},
				error : function(data) {
					console.log("获取设备失败: " + data);
				}
			});
    			
		});
		/* 更新设备信息，提交信息  */
		$('#btnEditDevice').click(function(){
			
			let sp_id         = editDevId;
			let sp_name       = $('#editSpName').val();
			let sp_desc       = $('#editSpDesc').val();
			let radar_ip      = $('#editRadarIP').val();
			let radar_port    = $('#editRadarPort').val();
			let ipcam_ip      = $('#editIPCamIP').val();
			let ipcam_name    = $('#editIPCamName').val();
			let ipcam_pwd     = $('#editIPCamPwd').val();
			let ipcam_url     = $('#editIPCamRTSP').val();
			let radar_status  = editDevRadarStatus;
			let ipcam_status  = editDevIPCamStatus
			console.log('update dev:'  + sp_id + sp_name + sp_desc + radar_ip + radar_port + ipcam_ip + ipcam_name + ipcam_pwd + radar_status + ipcam_status);
			console.log('update dev:'  + ipcam_url);
     		$.ajax({
				url : 'EditDeviceServlet',
				data : {
						'spId'      : sp_id,
						'spName'    : sp_name,
						'spDesc'    : sp_desc,
						'radarIP'   : radar_ip,
						'radarPort' : radar_port,
						'ipCamIP'   : ipcam_ip,
						'ipCamName' : ipcam_name,
						'ipCamPwd'  : ipcam_pwd,
						'ipCamRTSP' : ipcam_url,
					'radarStatus'   : radar_status,
					'ipcamStatus'   : ipcam_status
				},
				dataType : 'text',
				type : 'get',
				success : function(data) {
					console.log("更新设备成功!" + data);
				},
				error : function(data) {
					console.log("更新设备失败!" + data);
				}
			});
    			
		});    	
    });
    </script>
</head>
<body>
    <!-- 导航条 -->
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="javascript:void(0)">机场跑道异物监测系统管理 <span class="badge">v1.0</span></a>
          </div>
      
          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

            <ul class="nav navbar-nav navbar-right">
              <li><a href="#">欢迎：<span class="text-info">${loginName}</span></a></li>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">用户中心 <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#">修改信息</a></li>
                  <li role="separator" class="divider"></li>
                  <li><a href="#">退出登录</a></li>
                  <li role="separator" class="divider"></li>
                </ul>
              </li>
            </ul>
          </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
      </nav>
    <!-- 页面主题内容 -->
    <div class="container-fluid">
        
        <!-- 栅格系统 -->
        <div class="row">
            <!-- 菜单 -->
            <div class="col-sm-2">
                <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                    <div class="panel panel-default">
                      <div class="panel-heading" role="tab" id="headingOne">
                        <h4 class="panel-title">
                          <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                            <span class="glyphicon glyphicon-tasks"></span> 系统管理
                          </a>
                        </h4>
                      </div>
                      <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                        <div class="panel-body">
                            <ul class="list-group">
                                <li class="list-group-item"><button class="btn btn-primary" id="btnSysStatus">系统状态</button></li>
                                <li class="list-group-item"><button class="btn btn-primary" id="btnSysDataSave">数据管理</button></li>
                            </ul>
                        </div>
                      </div>
                    </div>

                    <div class="panel panel-default">
                      <div class="panel-heading" role="tab" id="headingTwo">
                        <h4 class="panel-title">
                          <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                            <span class="glyphicon glyphicon-th-large"></span> 设备组管理
                          </a>
                        </h4>
                      </div>
                      <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">
                        <div class="panel-body">
                            <ul class="list-group">
                                <li class="list-group-item"><button class="btn btn-primary" id="btnDevLst">设备列表</button></li>
                            </ul>
                        </div>
                      </div>
                    </div>

                    <div class="panel panel-default">
                      <div class="panel-heading" role="tab" id="headingThree">
                        <h4 class="panel-title">
                          <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                            <span class="glyphicon glyphicon-user"></span> 用户管理
                          </a>
                        </h4>
                      </div>
                      <div id="collapseThree" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingThree">
                        <div class="panel-body">
                            <ul class="list-group">
                                <li class="list-group-item"><button class="btn btn-primary" id="btnUsrLst">用户列表</button></li>
                            </ul>
                        </div>
                      </div>
                    </div>

                </div>

            </div>

            <!-- 页面中心内容 -->
            <div class="col-sm-10">
              <!-- 页头 -->
              <div class="page-header" style="margin-top: -20px;margin-bottom: 5px;">
                <h1>设备管理 </h1>
              </div>

              <!-- 标签页组件 -->
              <div>

                <!-- Nav tabs -->
                <ul class="nav nav-tabs" role="tablist">
                  <li role="presentation" class="active"><a href="#listDevice" aria-controls="listDevice" role="tab" data-toggle="tab">设备列表</a></li>
                  <li role="presentation"><a href="#addDevice" aria-controls="addDevice" role="tab" data-toggle="tab">添加设备</a></li>
                </ul>
              
                <!-- Tab panes -->
                <div class="tab-content">
                  <!-- 设备列表 #listDevice -->
                  <div role="tabpanel" class="tab-pane active" id="listDevice">
                    <!-- 处理用户列表的面板 -->
                    <div class="panel panel-default">

                      <div class="row">
                        <div class="col-sm-10 col-sm-offset-1">

                          <!-- 表格 -->
                          <table class="table">
                            <thead>
                              <tr>
                                <!-- <th>编号</th> -->
                                <th>名称</th>
                                <th>描述</th>
                                <th>雷达IP</th>
                                <th>雷达状态</th>
                                <th>摄像机IP</th>
                                <th>摄像机账号</th>
                                <th>摄像机密码</th>
                                <th>摄像机状态</th>
                                <th>操作</th>
                              </tr>
                            </thead>
                            <tbody id="dev-lst-tbody">
                              <c:forEach items="${newlist}" var="td">
                              <tr>
                                <%-- <th scope="row">${td.sp_id}</th> --%>
                                <td>${td.sp_name}</td>
                                <td>${td.sp_desc}</td>
                                <td>${td.radar_ip}</td>
                                <td>${td.radar_status}</td>
                                <td>${td.ipcam_ip}</td>
                                <td>${td.ipcam_name}</td>
                                <td>${td.ipcam_pwd}</td>
                                <td>${td.ipcam_status}</td>
                                <td>
                                  <button class="btn btn-danger btn-sm del-device" devId="${td.sp_id}">删除</button>
                                  <!-- <a href="" class="btn btn-danger btn-sm" >删除</a> -->
                                  <a href="" class="btn btn-info btn-sm mod-device" data-toggle="modal" data-target="#editDeviceModal" modId="${td.sp_id}">修改</a>
                                </td>
                               </tr>
                              </c:forEach>
                              
                            </tbody>
                          </table>

                          <!-- 分页组件 -->
                          <div class="pull-right">
                            <nav aria-label="Page navigation">
                              <ul class="pagination">
                                <li class="disable">
                                  <a href="#" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                  </a>
                                </li>
                                <li class="active"><a href="#">1</a></li>
                                <li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li>
                                  <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                  </a>
                                </li>
                              </ul>
                            </nav>
                          </div>

                        </div>

                      </div>


                    </div>

                    <!-- 处理消息提示 -->

                  </div>
                  
                  <!-- 添加设备 #addDevice -->
                  <div role="tabpanel" class="tab-pane" id="addDevice">
                    <!-- 添加设备表单 -->
                    <div class="panel panel-default">
                      <div class="panel-body">
                        <div class="row">
                          <div class="col-sm-10 col-sm-offset-1">
                            <!-- <form> -->
                              <div class="row">
                                <div class="col-sm-6">
                                  <div class="form-group">
                                    <label for="aa">监测点名称</label>
                                    <input type="text" class="form-control" id="addSpName" placeholder="输入简短名称">
                                  </div>
                                </div>
                                <div class="col-sm-6">
                                  <div class="form-group">
                                    <label for="bb">监测点简短描述</label>
                                    <input type="text" class="form-control" id="addSpDesc" placeholder="输入简短描述">
                                  </div>
                                </div>
                              </div>

                              <div class="row">
                                <div class="col-sm-6">
                                  <div class="form-group">
                                    <label for="bb">雷达IP</label>
                                    <input type="text" class="form-control" id="addRadarIP" placeholder="192.168.1.1">
                                  </div>
                                </div>
                                <div class="col-sm-6">
                                  <div class="form-group">
                                    <label for="bb">雷达端口</label>
                                    <input type="text" class="form-control" id="addRadarPort" placeholder="6000">
                                  </div>
                                </div>
                              </div>                             



                              <div class="form-group">
                                <label for="bb">摄像机IP</label>
                                <input type="text" class="form-control" id="addIPCamIP" placeholder="192.168.1.2">
                              </div>

                              <div class="row">
                                <div class="col-sm-6">
                                  <div class="form-group">
                                    <label for="bb">摄像机账号</label>
                                    <input type="text" class="form-control" id="addIPCamName" placeholder="admin">
                                  </div>
                                </div>
                                <div class="col-sm-6">
                                  <div class="form-group">
                                    <label for="bb">摄像机密码</label>
                                    <input type="text" class="form-control" id="addIPCamPwd" placeholder="abcd1234">
                                  </div>
                                </div>
                              </div>                                


                              <div class="row">
                                <label for="bb">摄像机RTSP地址</label>
                                <input type="text" class="form-control" id="addIPCamRTSP" placeholder="rtsp://admin:Abcd123456@192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1">
                              </div>
                              <button  class="btn btn-primary btn-block" id="btnAddDevice">提交</button>
                            <!-- </form> -->
                          </div>

                        </div>
                      </div>
                    </div>
                  
                  </div>
                </div>
              
              </div> 
            </div>


        </div>

        <!-- 修改模态框 -->
        <div class="modal fade" tabindex="-1" role="dialog" id="editDeviceModal">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title text-center">修改设备信息</h3>
              </div>
              <div class="modal-body">

                <form>
                  <div class="row">
                    <div class="col-sm-6">
                      <div class="form-group">
                        <label for="aa">监测点名称</label>
                        <input type="text" class="form-control" id="editSpName" placeholder="输入简短名称">
                      </div>
                    </div>
                    <div class="col-sm-6">
                      <div class="form-group">
                        <label for="bb">监测点简短描述</label>
                        <input type="text" class="form-control" id="editSpDesc" placeholder="输入简短描述">
                      </div>
                    </div>
                  </div>

                  <div class="row">
                    <div class="col-sm-6">
                      <div class="form-group">
                        <label for="bb">雷达IP</label>
                        <input type="text" class="form-control" id="editRadarIP" placeholder="192.168.1.1">
                      </div>
                    </div>
                    <div class="col-sm-6">
                      <div class="form-group">
                        <label for="bb">雷达端口</label>
                        <input type="text" class="form-control" id="editRadarPort" placeholder="6000">
                      </div>
                    </div>
                  </div>                             



                  <div class="form-group">
                    <label for="bb">摄像机IP</label>
                    <input type="text" class="form-control" id="editIPCamIP" placeholder="192.168.1.2">
                  </div>

                  <div class="row">
                    <div class="col-sm-6">
                      <div class="form-group">
                        <label for="bb">摄像机账号</label>
                        <input type="text" class="form-control" id="editIPCamName" placeholder="admin">
                      </div>
                    </div>
                    <div class="col-sm-6">
                      <div class="form-group">
                        <label for="bb">摄像机密码</label>
                        <input type="text" class="form-control" id="editIPCamPwd" placeholder="abcd1234">
                      </div>
                    </div>
                  </div>                                


                  <div class="form-group">
                    <label for="bb">摄像机RTSP地址</label>
                    <input type="text" class="form-control" id="editIPCamRTSP" placeholder="rtsp://admin:Abcd123456@192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1">
                  </div>
                  <!-- <button type="submit" class="btn btn-primary btn-block">提交</button> -->
                </form>                

              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="btnEditDevice">保存</button>
              </div>
            </div><!-- /.modal-content -->
          </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

    </div>

</body>

</html>